<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">

        <link rel="shortcut icon" href="<!--{eval echo register_static('img/touch-icon-57x57.png');}-->">

        <title>粉粉管理系统</title>

        <!-- Bootstrap core CSS -->
        <link href="<!--{eval echo register_static('css/bootstrap.min.css');}-->" rel="stylesheet">
        <link href="<!--{eval echo register_static('css/bootstrap-reset.css');}-->" rel="stylesheet">

        <!--Animation css-->
        <link href="<!--{eval echo register_static('css/animate.css');}-->" rel="stylesheet">

        <!--Icon-fonts css-->
        <link href="<!--{eval echo register_static('assets/font-awesome/css/font-awesome.css');}-->" rel="stylesheet" />
        <link href="<!--{eval echo register_static('assets/ionicon/css/ionicons.min.css');}-->" rel="stylesheet" />

        <link href="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.css');}-->" rel="stylesheet">

        <!-- Plugins css -->
        <link href="<!--{eval echo register_static('assets/modal-effect/css/component.css');}-->" rel="stylesheet">

        <!-- DataTables -->
        <link rel="stylesheet" href="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.css" rel="stylesheet');}-->" />

        <!-- Custom styles for this template -->
        <link href="<!--{eval echo register_static('css/style.css');}-->" rel="stylesheet">
        <link href="<!--{eval echo register_static('css/helper.css');}-->" rel="stylesheet">

        <!-- My styles for this template -->
        <link href="<!--{eval echo register_static('css/common.css');}-->" rel="stylesheet">

        <!-- layer -->
        <script src="<!--{eval echo register_static('layer/skin/layer.css');}-->"></script>
        <script src="<!--{eval echo register_static('layer/skin/layer.ext.css');}-->"></script>

    </head>

    <body>

        <!-- Aside Start-->
        <!--{template admin_v2/leftside}-->
        <!-- Aside Ends-->


        <!--Main Content Start -->
        <section class="content">

            <!-- Header -->
            <!--{template admin_v2/header}-->
            <!-- Header Ends -->


            <!-- Page Content Start -->
            <!-- ================== -->

            <div class="wraper container-fluid diary-topics">

            	<div class="row">
                    <div class="col-md-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h3 class="panel-title">圈子列表</h3>
                            </div>
                            <div class="panel-body">
                            	<div class="row">
                                	<div class="col-md-5 col-sm-5 col-xs-5">
	                                	<!-- Search -->
									    <form class="form-inline" role="form" action="admin.php?ac=group_class&op=findGroup" method="post" style="float:left;">
		                                    <div class="form-group">
                                                <input type="radio" name="option" id="optionsRadios1" value="1" checked>圈子名
                                                <input type="radio" name="option" id="optionsRadios2" value="2">圈子id
		                                        <input type="text" class="form-control"  placeholder="" name="text">
		                                    </div>
		                                    <button type="submit" class="btn btn-success m-l-10">点击搜索</button>
		                                </form>
		                            </div>
                                    <div class="col-md-2 col-sm-4 col-xs-4">
                                        <a href="admin.php?ac=group_class&op=getRecommendGroups&page=1" class="btn btn-primary topsort">推荐圈子列表</a>
                                    </div>
                            	</div>
                                <div class="row">
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <table id="datatable" class="table table-striped table-bordered">
                                            <thead>
                                                <tr>
                                                    <th>圈子id</th>
				                                    <th>名称</th>
				                                    <th>简介</th>
				                                    <th>创建者</th>
				                                    <th>组员数</th>
				                                    <th>话题数/今日新增</th>
				                                    <th>类别</th>
				                                    <th>创建时间</th>
				                                    <th>操作</th>
                                                </tr>
                                            </thead>

                                            <tbody>
                                            	<!--{loop $list $group}-->
                                                <tr>
                                                    <td><a target="_blank" href="{$webdomain}/group.php?ac=index&op=getTopicList&gid={$group['id']}" class="btn btn-primary btn-xs m-b-5 topic-name">
                                                        $group['id'] </a>
                                                        <!--{if $group['display'] > 1}-->
                                                        <button class="btn btn-success btn-xs m-b-5"> 已置顶 $group['display_score']</button>
                                                        <!--{/if}-->
                                                        <!--{if $group['is_recommend'] == 1}-->
                                                        <button class="btn btn-success btn-xs m-b-5"> 已推荐 </button>
                                                        <!--{/if}-->
                                                   </td>
				                                    <td><a href="{$webdomain}/group.php?ac=index&op=getTopicList&gid={$group['id']}" class="btn btn-primary btn-xs m-b-5 topic-name" target="_blank">
                                                        $group['name']</a>
                                                        <!--{if $group['is_pause'] > 0}-->
                                                        <button class="btn btn-warning btn-xs m-b-5"> 已封禁 <!--{date('Y-m-d H:i:s',$group['is_pause'])}--></button>
                                                        <!--{/if}-->
                                                    </td>
				                                    <td style="word-wrap:break-word;word-break:break-all" >$group['introduction']</td>
				                                    <td><a href="{$webdomain}/profile.php?ac=index&id=<!--{$group['user']['uid']}-->"  class="btn btn-info btn-xs m-b-5" target="_blank">$group['user']['nickname']</a></td>
				                                    <td>$group['member_num']</td>
				                                    <td>$group['topic_num']/$group['new_topic_num']</td>
				                                    <td>$group['categoryName']</td>
				                                    <td><!--{date('Y-m-d',$group['time'])}--></td>
				                                    <td class="actions" data-gid="$group['id']" data-type="$group['type']">
                                                        <div class="btn-group">
                                                            <button type="button" class="btn btn-success dropdown-toggle btn-sm" data-toggle="dropdown" aria-expanded="true">管理 <span class="caret"></span></button>
                                                            <ul class="dropdown-menu" role="menu">
                                                                <li><a target="_blank" href="http://ffweb.ffrj.net/group.php?ac=index&op=getTopicList&gid={$group['id']}">圈子详情</a></li>
                                                                <!--{if $group['display'] < 2}-->
                                                                <li><a href="#" class="top" data-gid="{$group['id']}">置顶圈子</a></li>
                                                                <!--{else}-->
                                                                <li><a href="#" class="removeTop" data-gid="{$group['id']}">取消置顶</a></li>
                                                                <!--{/if}-->
                                                                <!--{if $group['is_recommend'] < 1}-->
                                                                <li><a href="#" class="recommendGroup" data-gid="{$group['id']}">推荐圈子</a></li>
                                                                <!--{else}-->
                                                                <li><a href="#" class="removeRecommendGroup" data-gid="{$group['id']}">移除推荐圈子</a></li>
                                                                <!--{/if}-->
                                                                <li class="divider"></li>
                                                                <!--{if $group['is_pause'] < 1}-->
                                                                <li><a href="#" class="stop" data-gid="{$group['id']}">封禁</a></li>
                                                                <!--{else}-->
                                                                <li><a href="#" class="removeStop" data-gid="{$group['id']}">解除封禁</a></li>
                                                                <!--{/if}-->
                                                                <li><a href="#" class="remove" data-gid="{$group['id']}">解散圈子</a></li>
                                                                <li><a href="#" class="warning" data-gid="{$group['id']}">警告队长及管理</a></li>
                                                                <!--<li><a target="_blank" href="{$webdomain}/group.php?ac=index&op=groupEdit&gid={$group['id']}">修改圈子</a></li>-->
                                                                <li><a href="#" class="groupInfo" data-name="{$group['name']}" data-gid="{$group['id']}">修改圈子</a></li>
                                                            </ul>
                                                        </div>
                                                    </td>
				                                    </td>
                                                </tr>
                                                <!--{/loop}-->
                                             </tbody>
                                         </table>
                                         <!--{if $pageUrl}-->
		                                 <ul class="pager">
		                                    <li>
		                                        <a href="{$pageUrl['prev']}"> <i class="fa fa-angle-double-left"></i>上一页</a>
		                                    </li>
		                                    <li>
		                                        <a href="{$pageUrl['first']}"> <i class="fa"></i>第一页</a>
		                                    </li>
		                                    <li>
		                                        <a href="{$pageUrl['next']}">下一页 <i class="fa fa-angle-double-right"></i> </a>
		                                    </li>
		                                 </ul>
		                                 <!--{/if}-->
                                     </div>
                                 </div>
                             </div>
                         </div>
                     </div>
                 </div>

            </div>
            <!-- Page Content Ends -->
            <!-- ================== -->

            <div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">

  			</div><!-- /.modal -->


            <!-- Footer Start -->
            <!--{template admin_v2/footer}-->
            <!-- Footer Ends -->



        </section>
        <!-- Main Content Ends -->


        <!-- js placed at the end of the document so the pages load faster -->
        <script src="<!--{eval echo register_static('js/jquery.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/bootstrap.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/pace.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/wow.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/jquery.nicescroll.js');}-->" type="text/javascript"></script>

		<script src="<!--{eval echo register_static('js/jquery.app.js');}-->"></script>

        <script src="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/datatables/dataTables.bootstrap.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.init.js');}-->"></script>

        <!-- Modal-Effect -->
        <script src="<!--{eval echo register_static('assets/modal-effect/js/classie.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/modal-effect/js/modalEffects.js');}-->"></script>

        <!--layer-->
        <script src="<!--{eval echo register_static('layer/layer.js');}-->"></script>
        <script src="<!--{eval echo register_static('layer/extend/layer.ext.js');}-->"></script>

        <script type="text/template" id="editsource">
            {{#.}}
            <form id="editgrouptypeForm">
                <div class="form-group">
                    <label class="control-label col-lg-2">介绍</label>
                    <div class="col-lg-10">
                        <input class="layui-input" placeholder="自定义日期格式" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" />
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-lg-offset-2 col-lg-10">
                        <br/>
                        <input type="hidden" name="cid" value="{{this.cid}}">
                        <input type="hidden" name="ac" value="group_class">
                        <input type="hidden" name="op" value="manageGroupCategories">
                        <button class="btn btn-primary" id="editgrouptype" type="button">修改</button>
                    </div>
                </div>
            </form>
            {{/.}}
        </script>

		<script type="text/javascript">
            $(document).ready(function() {
            	// 设置table配置
                $('#datatable').dataTable({
                    "iDisplayLength": 50,
                    "aLengthMenu": [10, 20, 50, 100],
                    "searching": false,
                    "bLengthChange" : false,
                    "bSort" : true,
                    "bPaginate": false,
                    "aaSorting": [
                        [ 3, "desc" ]
                    ]
                });

                // 置顶
                $(".top").click(function() {
                    var group = $(this).data();
                    var gid = group.gid;

                    layer.confirm('确定置顶！', function (index) {
                        layer.prompt({
                            title: '请输入排序值',
                        }, function (value, index, elem) {
                            //暂停使用
                            $.ajax({
                                url: "admin.php?ac=group_class&op=setTopGroup",
                                type: "POST",
                                data: {gid: gid, score: value},
                                success: function (data) {
                                    if (data) {
                                        swal("置顶完成!", "圈子已置顶", "success");
                                        setTimeout(refresh(), 3000);
                                    } else {
                                        swal("置顶失败!", "圈子置顶失败！", "error");
                                    }
                                }
                            });
                            layer.close(index);
                        });
                    });
                });
                // 取消置顶
                $(".removeTop").click(function() {
                    var group = $(this).data();
                    var gid = group.gid;

                    layer.confirm('确定取消置顶？', function (index) {
                        //暂停使用
                        $.ajax({
                            url: "admin.php?ac=group_class&op=removeTopGroup",
                            type: "POST",
                            data: {gid: gid},
                            success: function (data) {
                                if (data) {
                                    swal("取消置顶完成!", "圈子已取消置顶", "success");
                                    setTimeout(refresh(), 3000);
                                } else {
                                    swal("取消置顶失败!", "圈子取消置顶失败！", "error");
                                }
                            }
                        });
                        layer.close(index);
                    });
                });

                // 推荐
                $(".recommendGroup").click(function() {
                    var group = $(this).data();
                    var gid = group.gid;

                    layer.confirm('确定推荐？', function (index) {
                        layer.prompt({
                            title: '请输入排序值',
                        }, function (value, index, elem) {
                            //暂停使用
                            $.ajax({
                                url: "admin.php?ac=group_class&op=recommendGroup",
                                type: "POST",
                                data: {gid: gid, score: value},
                                success: function (data) {
                                    if (data) {
                                        swal("推荐成功!", "推荐成功", "success");
                                        setTimeout(refresh(), 3000);
                                    } else {
                                        swal("推荐失败!", "推荐失败！", "error");
                                    }
                                }
                            });
                            layer.close(index);
                        });
                    });
                });
                // 取消推荐
                $(".removeRecommendGroup").click(function() {
                    var group = $(this).data();
                    var gid = group.gid;

                    layer.confirm('确定取消推荐？', function (index) {
                        $.ajax({
                            url: "admin.php?ac=group_class&op=removeRecommendGroup",
                            type: "POST",
                            data: {gid: gid},
                            success: function (data) {
                                if (data) {
                                    swal("取消成功!", "取消成功", "success");
                                    setTimeout(refresh(), 3000);
                                } else {
                                    swal("取消失败!", "取消失败！", "error");
                                }
                            }
                        });
                        layer.close(index);
                    });
                });
                // 解除封禁
                $(".removeStop").click(function() {
                    var group = $(this).data();
                    var gid = group.gid;

                    layer.confirm('解除封禁？', function (index) {
                        $.ajax({
                            url: "admin.php?ac=group_class&op=removePauseGroup",
                            type: "POST",
                            data: {gid: gid},
                            success: function (data) {
                                if (data) {
                                    swal("解除封禁成功!", "解除封禁成功", "success");
                                    setTimeout(refresh(), 3000);
                                } else {
                                    swal("解除封禁失败!", "解除封禁失败！", "error");
                                }
                            }
                        });
                        layer.close(index);
                    });
                });

                // 封禁使用
                $(".stop").click(function() {
                    var group = $(this).data();
                    var gid = group.gid;

                    layer.confirm('确定封禁?', function (index) {
                        layer.prompt({
                            title: '请输入正整数，以小时为单位，到期自动解禁',
                        }, function (value, index, elem) {
                            var patt = /^\d+$/;
                            if (patt.test(value)) {
                                //暂停使用
                                $.ajax({
                                    url: "admin.php?ac=group_class&op=pauseGroup",
                                    type: "POST",
                                    data: {gid: gid, time: value},
                                    success: function (data) {
                                        if (data) {
                                            swal("封禁成功!", "该圈子已被封禁", "success");
                                            setTimeout(refresh(), 3000);
                                        } else {
                                            swal("封禁失败!", "圈子封禁出现了问题！", "error");
                                        }
                                    }
                                });
                            } else {
                                layer.alert('只能输入正整数');
                            }
                            layer.close(index);
                        });
                    });
                });

                // 警告圈子队长及管理
                $(".warning").click(function() {
                    var group = $(this).data();
                    var gid = group.gid;

                    layer.confirm('确定警告?确定后不可撤销！', function (index) {
                        layer.prompt({
                            formType: 2,
                            title: '请输入警告原因',
                        }, function (value, index, elem) {
                            //暂停使用
                            $.ajax({
                                url: "admin.php?ac=group_class&op=warning",
                                type: "POST",
                                data: {gid: gid, reason: value},
                                success: function (data) {
                                    if (data) {
                                        swal("警告完成!", "该圈子管理将收到警告的私信", "success");
                                    } else {
                                        swal("警告失败!", "警告圈子管理出现了问题！", "error");
                                    }
                                }
                            });
                            layer.close(index);
                        });
                    });
                });

                // 解散圈子
                $(".remove").click(function() {
                    var group = $(this).data();
                    var gid = group.gid;

                    layer.confirm('确定解散?解散后不可撤销！', function (index) {
                        layer.prompt({
                            formType: 2,
                            title: '请输入解散原因',
                        }, function (value, index, elem) {
                            //暂停使用
                            $.ajax({
                                url: "admin.php?ac=group_class&op=removeGroup",
                                type: "POST",
                                data: {gid: gid, reason: value},
                                success: function (data) {
                                    if (data) {
                                        swal("解散完成!", "该圈子已被解散", "success");
                                        setTimeout(refresh(), 3000);
                                    } else {
                                        swal("解散失败!", "解散圈子出现了问题！", "error");
                                    }
                                }
                            });
                            layer.close(index);
                        });
                    });
                });

                // 获取圈子详情
                $(".groupInfo").click(function() {
                    var group = $(this).data();
                    var gid = group.gid;
                    var name = group.name;
                    $.ajax(
                        {
                            url     :   "admin.php?ac=group_class&op=getGroupInfo",
                            type    :   "POST",
                            data    :   {gid : gid},
                            success :   function(data)
                            {
                                layer.open({
                                    type: 1,
                                    title: name,
                                    closeBtn: 1,
                                    area:['700px', '80%'],
                                    shadeClose: true,
                                    content: data
                                });
                            }
                        });
                });

                // 编辑圈子信息
                $(document).on("click",".editGroup",function(){
                    var param   =   $("#from").serialize();
                    var introduction = $("#field-8").val();
                    if(introduction.length > 200){
                        alert('长度限制200');
                        return false;
                    }
                    console.log(param);
                    $.ajax(
                        {
                            url     :   "admin.php?ac=group_class&op=editGroup",
                            type    :   "POST",
                            data    :   param,
                            success :   function(data)
                            {
                                layer.closeAll('page');
                                if (data) {
                                    swal("编辑成功!", "该话题已经被成功编辑！", "success");
                                    setTimeout(refresh(), 3000);
                                }else{
                                    swal("编辑失败!", "编辑该话题时出现了问题！", "error");
                                }
                            }
                        });
                });


             	// 刷新当前页面
        		function refresh(){
        		    setInterval(window.location.reload(),5000);
        		}

                function stopGroup(gid) {
                    layer.prompt({
                        formType: 2,
                        value: '初始值',
                        title: '请输入值',
                        area: ['100px', '35px'] //自定义文本域宽高
                    }, function(value, index, elem){
                        alert(value); //得到value
                        layer.close(index);
                    });
                    alert(gid);
                }
            } );
        </script>
    </body>
</html>
